<template>
  <div class="icons">
    <swiper  :options="swiperOption">
      <!-- slides -->
      <swiper-slide v-for="(page, index)
                    of
                    pages"
                    :key="index">
        <div class="icon"
             v-for="item
                    of
                    page"
                    :key="item.id">
          <div class="icon-img">
            <img :src="item.url" class="icon-content"/>
          </div>
          <div class="icon-desc">{{item.desc}}</div>
        </div>
      </swiper-slide>

      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>

export default {
  name: 'Icons',
  props: {
    dataList: Array
  },
  data: function () {
    return {
      swiperOption: {
        autoPlay: false
      }
    }
  },
  computed: {
    pages: function () {
      const ret = []
      this.dataList.forEach((value, index) => {
        const page = Math.floor(index / 8)
        if (!ret[page]) {
          ret[page] = []
        }
        ret[page].push(value)
      })
      return ret
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  @import '~styles/mixins.styl'
  .icons >>> .swiper-container
    overflow: hidden
    height: 0
    padding-bottom: 50%
  .icons
    margin-top: .1rem
    .icon
      overflow: hidden
      height: 0
      padding-bottom: 25%
      width: 25%
      float: left
      position: relative
      .icon-img
        position: absolute
        top: 0
        left: 0
        right: 0
        bottom: .22rem
        .icon-content
          height: 80%
          margin: 0 auto
          display: block
      .icon-desc
        position: absolute
        bottom: .11rem
        left: 0
        right: 0
        text-align: center
        color: $darkTextColor
        ellipse()
</style>
